<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>lenarray</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="ksmps.html" title="ksmps" />
    <link rel="next" href="lfo.html" title="lfo" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">lenarray</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="ksmps.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="lfo.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="lenarray"></a>
      <div class="titlepage"></div>
      <a id="IndexLenarray" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">lenarray</span>
        </h2>
        <p>lenarray — 
      Evaluates the size or shape length of an array.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp118463472"></a>
        <h2>Description</h2>
        <p>
      Evaluates the size or number of dimensions of an array.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp118539312"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ir <span class="command"><strong>lenarray</strong></span> karray[, iwhich]</pre>
        <pre class="synopsis">kr <span class="command"><strong>lenarray</strong></span> karray[, iwhich]</pre>
      </div>
      <div class="refsect1">
        <a id="idp118542864"></a>
        <h2>Initialisation</h2>
        <p>
      <span class="emphasis"><em>karray</em></span> -- The array that is being
      questioned.  It can be of any dimension.
    </p>
        <p>
      <span class="emphasis"><em>iwhich</em></span> -- selects which dimension to
      evaluate the size.  If zero or negative it selects the number of
      dimensions.  It defaults to 1, as used in a vector.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp118545536"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kr</em></span> -- length of vector.
    </p>
        <p>
      <span class="emphasis"><em>karray</em></span> -- array to query.
    </p>
        <p>
      If the dimension requested is larger than the actual array, or
      the array is not initialised the value -1 is returned.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp118548528"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the lenarray opcode. It uses the file <a class="ulink" href="examples/lenarray.csd" target="_top"><em class="citetitle">lenarray.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp118550384"></a>
          <p class="title">
            <strong>Example 416. Example of the lenarray opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-n -m128 <span class="comment">;no sound output, reduced messages</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="comment">;example by joachim heintz</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 1
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

  <span class="oblock">instr</span> 1 <span class="comment">;simple example</span>
kArr[]  <span class="opc">fillarray</span> 1, 2, 3, 4 <span class="comment">;fill array manually</span>
        <span class="opc">printks</span> "Length of kArr <span class="op">=</span> <span class="op">%</span>d\n\n", 0, <span class="opc">lenarray</span>(kArr) <span class="comment">;print out its length</span>
        <span class="opc">turnoff</span> <span class="comment">;only do this in the first k-cycle</span>
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> 2 <span class="comment">;random array length</span>
iNumEls <span class="opc">random</span>  1, 11 <span class="comment">;create random number between 1 and 10</span>
kArr[]  <span class="opc">init</span>    <span class="opc">int</span>(iNumEls) <span class="comment">;create array of this length</span>
        <span class="opc">printks</span> "Random length of kArr <span class="op">=</span> <span class="op">%</span>d\n", 0, <span class="opc">lenarray</span>(kArr) <span class="comment">;print out</span>
        <span class="opc">turnoff</span>
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> 3 <span class="comment">;fill random array length with random elements</span>
iNumEls <span class="opc">random</span>  1, 11 <span class="comment">;create random number between 1 and 10</span>
kArr[]  <span class="opc">init</span>    <span class="opc">int</span>(iNumEls) <span class="comment">;create array of this length</span>
        <span class="opc">printks</span> "Random length of kArr <span class="op">=</span> <span class="op">%</span>d\n", 0, <span class="opc">lenarray</span>(kArr) <span class="comment">;print out</span>

<span class="comment">;fill</span>
kIndx   <span class="op">=</span>       0 <span class="comment">;initialize index</span>
  until kIndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr) do
kArr[kIndx] <span class="opc">rnd31</span> 10, 0 <span class="comment">;set element to random value -10...10</span>
kIndx   <span class="op">+</span><span class="op">=</span>      1 <span class="comment">;increase index</span>
  od

<span class="comment">;print</span>
kIndx   <span class="op">=</span>       0 <span class="comment">;initialize index</span>
  until kIndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr) do
<span class="opc">printf</span>("kArr[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kIndx<span class="op">+</span>1, kIndx, kArr[kIndx])
kIndx   <span class="op">+</span><span class="op">=</span>      1 <span class="comment">;increase index</span>
  od

        <span class="opc">turnoff</span>
  <span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 .1
<span class="stamnt">i</span> 2 0 .1 
<span class="stamnt">i</span> 2 0 .1
<span class="stamnt">i</span> 3 0 .1
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp118554672"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="vectorial.html" title="Vectorial Opcodes"><em class="citetitle"></em>Vectorial opcodes</a>
</p>
      </div>
      <div class="refsect1">
        <a id="idp118556720"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: John ffitch</td>
          </tr>
          <tr>
            <td>Codemist Ltd</td>
          </tr>
          <tr>
            <td>2013</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 6.00</p>
        <p>Extended to multi-dimensions in 6.04</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="ksmps.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="lfo.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">ksmps </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> lfo</td>
        </tr>
      </table>
    </div>
  </body>
</html>
